//
//  AddAndDelTableViewController.m
//  NaviAndTable
//
//  Created by student on 16/3/7.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "AddAndDelTableViewController.h"

@interface AddAndDelTableViewController ()
{
    BOOL bAdded;//保存当前时候添加 一行“添加新同学”的格子
}

@property (nonatomic,strong) NSMutableArray *mList;


@end

@implementation AddAndDelTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.mList = [@[@"张三",@"李四",@"王五"] mutableCopy];
    
    //导航栏右侧添加按钮
    
    UIBarButtonItem *moveBtn = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(toggleMove)];
    
    self.navigationItem.rightBarButtonItem = moveBtn;
}

//切换表格状态
- (void)toggleMove
{
    [self.tableView setEditing:!self.tableView.editing animated:YES];
    //根据表格的状态编辑，切换按钮文字
    [self.navigationItem.rightBarButtonItem setTitle:self.tableView.editing?@"完成":@"编辑"];
    
    if (self.tableView.editing && !bAdded)
    {
        bAdded = YES;
        NSIndexPath *tmpPath = [NSIndexPath indexPathForItem:self.mList.count inSection:0];
        [self.tableView insertRowsAtIndexPaths:@[tmpPath]withRowAnimation:UITableViewRowAnimationLeft];
        
    }
    
    
    
    
    
    
}


@end
